package com.example.codec;

import io.netty.buffer.ByteBuf;
import org.jboss.marshalling.ByteOutput;

import java.io.IOException;

/**
 * <p>  </p>
 *
 * @author Chris
 * @since 2024/3/30 10:25
 */
public class ByteOutputAdapter implements ByteOutput {

    private final ByteBuf buffer;


    public ByteOutputAdapter(ByteBuf byteBuf) {
        this.buffer = byteBuf;
    }

    @Override
    public void write(int b) throws IOException {
        buffer.writeByte(b);
    }

    @Override
    public void write(byte[] b) throws IOException {
        buffer.writeBytes(b);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        buffer.writeBytes(b, off, len);
    }

    @Override
    public void close() throws IOException {

    }

    @Override
    public void flush() throws IOException {

    }

    public ByteBuf getBuffer() {
        return buffer;
    }
}